package com.bac.rentmap.web.controller.osmimport;

import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bac.rentmap.manager.BuildingManager;
import com.bac.rentmap.model.Building;
import com.bac.rentmap.osm.BuildingsReader;

import java.util.List;

/**
 *
 * @author Ivan Holub
 */
public class BuildingsController extends AbstractController {

    private String viewName;

    private BuildingManager buildingManager;

    private BuildingsReader buildingsReader;

    public void setBuildingsReader(BuildingsReader buildingsReader) {
        this.buildingsReader = buildingsReader;
    }

    public void setBuildingManager(BuildingManager buildingManager) {
        this.buildingManager = buildingManager;
    }

    public void setViewName(String viewName) {
        this.viewName = viewName;
    }

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        ModelAndView mav = new ModelAndView(viewName);
        List<Building> buildings = buildingManager.getBuildings(100);
//        List<Building> buildings = buildingsReader.readBuildings(getServletContext());
        mav.addObject("buildingsSize", buildings.size());
        mav.addObject("buildings", buildings);
        return mav;
    }
}
